<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>MyBatis 类型处理器深度解析</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            position: relative;
            overflow: hidden;
        }
        
        .hero-gradient::before {
            content: '';
            position: absolute;
            top: -50%;
            right: -50%;
            bottom: -50%;
            left: -50%;
            background: radial-gradient(circle, rgba(255,255,255,0.1) 0%, transparent 70%);
            animation: pulse 4s ease-in-out infinite;
        }
        
        @keyframes pulse {
            0%, 100% { transform: scale(1); opacity: 0.5; }
            50% { transform: scale(1.1); opacity: 0.8; }
        }
        
        .content-card {
            background: rgba(255, 255, 255, 0.95);
            backdrop-filter: blur(10px);
            box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
            transition: all 0.3s ease;
        }
        
        .content-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 25px 50px rgba(0, 0, 0, 0.15);
        }
        
        .section-title {
            position: relative;
            padding-left: 20px;
        }
        
        .section-title::before {
            content: '';
            position: absolute;
            left: 0;
            top: 50%;
            transform: translateY(-50%);
            width: 4px;
            height: 24px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border-radius: 2px;
        }
        
        .code-block {
            background: #1e1e1e;
            color: #d4d4d4;
            border-radius: 12px;
            overflow: hidden;
            position: relative;
        }
        
        .code-block::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            height: 40px;
            background: #2d2d2d;
            border-bottom: 1px solid #3e3e3e;
        }
        
        .code-block pre {
            padding: 60px 24px 24px;
            overflow-x: auto;
            margin: 0;
        }
        
        .feature-card {
            background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
            color: white;
            padding: 24px;
            border-radius: 16px;
            transition: all 0.3s ease;
            position: relative;
            overflow: hidden;
        }
        
        .feature-card::before {
            content: '';
            position: absolute;
            top: -50%;
            right: -50%;
            width: 200%;
            height: 200%;
            background: radial-gradient(circle, rgba(255,255,255,0.2) 0%, transparent 70%);
            animation: rotate 10s linear infinite;
        }
        
        @keyframes rotate {
            0% { transform: rotate(0deg); }
            100% { transform: rotate(360deg); }
        }
        
        .feature-card:hover {
            transform: translateY(-8px) scale(1.02);
            box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
        }
        
        .mermaid {
            background: white;
            padding: 20px;
            border-radius: 12px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
        }
        
        .highlight-text {
            background: linear-gradient(120deg, #f093fb 0%, #f5576c 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
            font-weight: 700;
        }
        
        .floating-icon {
            animation: float 3s ease-in-out infinite;
        }
        
        @keyframes float {
            0%, 100% { transform: translateY(0); }
            50% { transform: translateY(-10px); }
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <div class="hero-gradient text-white py-20 relative">
        <div class="container mx-auto px-6 relative z-10">
            <div class="text-center">
                <div class="floating-icon inline-block mb-6">
                    <i class="fas fa-exchange-alt text-6xl opacity-90"></i>
                </div>
                <h1 class="text-5xl md:text-6xl font-bold mb-6">MyBatis 类型处理器</h1>
                <p class="text-xl md:text-2xl opacity-90 max-w-3xl mx-auto leading-relaxed">
                    深入理解 TypeHandler 接口，掌握 Java 类型与数据库类型之间的优雅转换艺术
                </p>
            </div>
        </div>
    </div>

    <!-- Main Content -->
    <div class="container mx-auto px-6 py-12">
        <!-- Introduction Card -->
        <div class="content-card rounded-2xl p-8 mb-12">
            <div class="prose max-w-none">
                <p class="text-lg leading-relaxed text-gray-700 indent-8">
                    MyBatis 使用 <code class="bg-purple-100 text-purple-800 px-2 py-1 rounded">TypeHandler</code> 接口来处理 Java 类型和数据库类型之间的转换。通过提供默认的和自定义的类型处理器，MyBatis 能够支持多种数据类型，并且允许开发者为特定需求定制转换逻辑。这种设计使得数据映射更加灵活和高效。
                </p>
            </div>
        </div>

        <!-- Overview Section -->
        <div class="content-card rounded-2xl p-8 mb-12">
            <h2 class="section-title text-3xl font-bold mb-6 text-gray-800">
                <i class="fas fa-layer-group mr-3 text-purple-600"></i>类型处理器概述
            </h2>
            <p class="text-lg leading-relaxed text-gray-700 indent-8">
                类型处理器是 MyBatis 的核心组件之一，负责在 Java 类型和数据库类型之间进行转换。它使得 MyBatis 能够将 SQL 查询结果映射到 Java 对象，并将 Java 对象插入到数据库中。
            </p>
        </div>

        <!-- How it Works Section -->
        <div class="content-card rounded-2xl p-8 mb-12">
            <h2 class="section-title text-3xl font-bold mb-6 text-gray-800">
                <i class="fas fa-cogs mr-3 text-purple-600"></i>工作原理
            </h2>
            <p class="text-lg leading-relaxed text-gray-700 indent-8 mb-6">
                MyBatis 使用 <code class="bg-purple-100 text-purple-800 px-2 py-1 rounded">TypeHandler</code> 接口来处理这些转换。<code class="bg-purple-100 text-purple-800 px-2 py-1 rounded">TypeHandler</code> 是一个接口，提供了四个主要的方法：
            </p>
            
            <div class="grid md:grid-cols-2 gap-6">
                <div class="bg-gradient-to-br from-purple-50 to-pink-50 p-6 rounded-xl border border-purple-200">
                    <h4 class="font-semibold text-purple-800 mb-3 flex items-center">
                        <i class="fas fa-database mr-2"></i>setParameter
                    </h4>
                    <code class="text-sm text-gray-700 block mb-2">setParameter(PreparedStatement ps, int i, T parameter, JdbcType jdbcType)</code>
                    <p class="text-gray-600">将 Java 类型的参数设置到 PreparedStatement 中。</p>
                </div>
                
                <div class="bg-gradient-to-br from-purple-50 to-pink-50 p-6 rounded-xl border border-purple-200">
                    <h4 class="font-semibold text-purple-800 mb-3 flex items-center">
                        <i class="fas fa-table mr-2"></i>getResult (按列名)
                    </h4>
                    <code class="text-sm text-gray-700 block mb-2">getResult(ResultSet rs, String columnName)</code>
                    <p class="text-gray-600">从 ResultSet 中获取数据库字段值，并转换为 Java 类型。</p>
                </div>
                
                <div class="bg-gradient-to-br from-purple-50 to-pink-50 p-6 rounded-xl border border-purple-200">
                    <h4 class="font-semibold text-purple-800 mb-3 flex items-center">
                        <i class="fas fa-list-ol mr-2"></i>getResult (按索引)
                    </h4>
                    <code class="text-sm text-gray-700 block mb-2">getResult(ResultSet rs, int columnIndex)</code>
                    <p class="text-gray-600">从 ResultSet 中获取数据库字段值，并转换为 Java 类型（按列索引）。</p>
                </div>
                
                <div class="bg-gradient-to-br from-purple-50 to-pink-50 p-6 rounded-xl border border-purple-200">
                    <h4 class="font-semibold text-purple-800 mb-3 flex items-center">
                        <i class="fas fa-code mr-2"></i>getResult (存储过程)
                    </h4>
                    <code class="text-sm text-gray-700 block mb-2">getResult(CallableStatement cs, int columnIndex)</code>
                    <p class="text-gray-600">从 CallableStatement 中获取数据库字段值，并转换为 Java 类型。</p>
                </div>
            </div>
        </div>

        <!-- Visualization -->
        <div class="content-card rounded-2xl p-8 mb-12">
            <h2 class="section-title text-3xl font-bold mb-6 text-gray-800">
                <i class="fas fa-project-diagram mr-3 text-purple-600"></i>类型转换流程
            </h2>
            <div class="mermaid">
                graph LR
                    A[Java对象] -->|TypeHandler| B[PreparedStatement]
                    B -->|SQL执行| C[数据库]
                    C -->|查询结果| D[ResultSet]
                    D -->|TypeHandler| E[Java对象]
                    
                    style A fill:#f093fb,stroke:#333,stroke-width:2px,color:#fff
                    style E fill:#f093fb,stroke:#333,stroke-width:2px,color:#fff
                    style C fill:#667eea,stroke:#333,stroke-width:2px,color:#fff
                    style B fill:#ffd93d,stroke:#333,stroke-width:2px
                    style D fill:#ffd93d,stroke:#333,stroke-width:2px
            </div>
        </div>

        <!-- Default Type Handlers -->
        <div class="content-card rounded-2xl p-8 mb-12">
            <h2 class="section-title text-3xl font-bold mb-6 text-gray-800">
                <i class="fas fa-box mr-3 text-purple-600"></i>默认类型处理器
            </h2>
            <p class="text-lg leading-relaxed text-gray-700 indent-8 mb-6">
                MyBatis 提供了一些默认的类型处理器来处理常见的 Java 和数据库类型之间的转换，例如：
            </p>
            
            <div class="grid md:grid-cols-3 gap-6">
                <div class="text-center p-6 bg-gradient-to-br from-blue-50 to-indigo-50 rounded-xl">
                    <i class="fas fa-font text-4xl text-blue-600 mb-4"></i>
                    <h4 class="font-semibold text-gray-800 mb-2">StringTypeHandler</h4>
                    <p class="text-gray-600">用于处理 String 类型</p>
                </div>
                
                <div class="text-center p-6 bg-gradient-to-br from-green-50 to-emerald-50 rounded-xl">
                    <i class="fas fa-hashtag text-4xl text-green-600 mb-4"></i>
                    <h4 class="font-semibold text-gray-800 mb-2">IntegerTypeHandler</h4>
                    <p class="text-gray-600">用于处理 Integer 类型</p>
                </div>
                
                <div class="text-center p-6 bg-gradient-to-br from-orange-50 to-red-50 rounded-xl">
                    <i class="fas fa-calendar text-4xl text-orange-600 mb-4"></i>
                    <h4 class="font-semibold text-gray-800 mb-2">DateTypeHandler</h4>
                    <p class="text-gray-600">用于处理 Date 类型</p>
                </div>
            </div>
        </div>

        <!-- Custom Type Handler -->
        <div class="content-card rounded-2xl p-8